<div id=billing>
<% unless current_user.has_role? "admin" %>
<h1><%= t("listing_users") %></h1>
<%else%>
<h1><%= t("listing_owners") %></h1>
<%end%>
<table class="index" id='listing_users'>
  <thead>
  <tr>
    <%= hook :admin_users_index_headers do %>
		<% unless current_user.has_role? "admin" %>
      <th><%= sort_link @search,:email,t("user"),{}, {:title => 'users_email_title'} %></th>
      <th>
        <%= hook :admin_users_index_header_actions %>
      </th>
			<%else%>
			<th><%= t("store_name") %></th>
		 <th><%= t("owner_name") %></th>
		 <th><%= t("custom_domain")%>
			<th><%= t("status") %></th>
			<th><%= t("view_details") %></th>
    <% end %>
    <% end %>
  </tr>
  </thead>
  <tbody>
	<% unless current_user.has_role? "admin" %>
    <% @users.each do |user|%>
      <tr id="<%= dom_id user %>">
        <%- locals = {:user => user} %>
        <%= hook :admin_users_index_rows, locals do %>
          <td width="350px" class='user_email'><%=link_to user.email, object_url(user) %></td>
        <% end %>
        <td>
          <%= hook :admin_users_index_row_actions, locals do %>
            <%= link_to_edit user, :class => "edit" %> &nbsp;
            <%= link_to_delete user %>
          <% end %>
        </td>
      </tr>
    <% end %>
		<%else%>
<% @users.each do |user|%>
    <% store= store_owner=StoreOwner.find_by_user_id(user.id) %>
      <tr id="<%= dom_id user %>">
        <%- locals = {:user => user} %>
        <%= hook :admin_users_index_rows, locals do %>
				<% link_path=store.domain+"."+APP_CONFIG['domain_url'].split("//")[1]%>
					<td width="200px" class='user_email'><%=link_to link_path,"http://#{link_path}",:target=>"_blank"%></td>
          <td width="200px" class='user_email'><%=store.first_name%></td>
					<%store.domain_customize%>
					<% if store.domain_customize%>
					<%domain_url=store.domain_customize.custom_domain%>
				<td width="200px" class='user_email'><%=link_to domain_url,"http://#{domain_url}",:target=>"_blank"%></td>
				<% else %>
								<td width="200px" class='user_email'><%="Unavailable"%></td>

					<%end%>

				<td width="200px" class='user_email'><%= link_to (store.is_active?) ? "Active" : "Inactive",'#',:onclick => "check_status(#{store.id});"%></td>
				<% end %>
        <td>
          <%= hook :admin_users_index_row_actions, locals do %>
 <%= link_to "View details",'#',:onclick => "viewdetails(#{store.id});"%>					<%#= link_to_delete user %>
          <% end %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>

<% end %>
<% unless current_user.has_role? "admin" %>
	 </tbody>
</table>


<% content_for :sidebar do %>
  <div class="box">
    <h3><%= t(:search) %></h3>
    <% @search = User.search %>
    <%= form_for [:admin, @search] do |f| %>
      <%- locals = {:f => f} %>
      <%= hook :admin_users_index_search, locals do %>
        <p>
          <%= t("email") %><br />
          <%= f.text_field :email_contains, :size=>18 %>
        </p>
      <% end %>
      <%= hook :admin_users_index_search_buttons, locals do %>
        <p><%= button t("search") %></p>
      <% end %>
    <% end %>
  </div>
<% end %>

<%end%>
</div>

<script>
function viewdetails(id){
{
$.ajax({
                        url:"/admin/store_details/billing_history",
                        data: "store="+id,
												success: function(data) {
			$('#status').html(data);
			}
                        });
}
}
function check_status(store)
{
$.ajax({
			url: "/admin/users/store_status",
			data: "userid="+store,
			
});
		}
</script>